package cn.psvmc.cxzapi.controller.order;

import cn.psvmc.cxzapi.model.common.*;
import cn.psvmc.cxzapi.model.customer.TCustomerAuth;
import cn.psvmc.cxzapi.model.goods.TGoods;
import cn.psvmc.cxzapi.model.order.*;
import cn.psvmc.cxzapi.response.*;
import cn.psvmc.cxzapi.service.order.TOrderService;
import cn.psvmc.cxzapi.util.PageUtil;
import cn.psvmc.cxzapi.util.ToolUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 订单管理
 *
 * @Author auto
 * @Date 2024-08-12
 */
@RestController
@RequestMapping("/order")
public class TOrderController {

    @Resource
    private TOrderService tOrderService;

    /**
     * @Description 修改押金
     * @Date 2024/9/14 22:40
     * @Author YWX
     * @Param [tOrder]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/edit_deposit")
    public Result editDeposit(@RequestBody TOrder tOrder) {
        ToolUtils.validation(new Object[]{tOrder.getOrderId(), "id", 1, tOrder.getRversion(), "版本", 1, tOrder.getDeposit(), "押金", 2});
        tOrderService.editDeposit(tOrder);
        return ResultGenerator.genSuccessResult("修改成功！");
    }

    /**
     * @Author auto 2024-08-12 查询订单表详情
     * @Param [entity] 查询实体类
     * @Return cn.psvmc.cxzapi.response.Result
     */
    @PostMapping("/detail")
    public Result detail(@RequestBody OrderEntity entity) {
        Integer id = entity.getOrderId();
        ToolUtils.validation(new Object[]{id, "id", 1});
        return ResultGenerator.genSuccessResult("查询成功", tOrderService.detail(id));
    }

    /**
     * @Author auto 2024-08-12 查询订单表列表
     * @Param entity 分页查询通用实体类
     * @Return cn.psvmc.cxzapi.response.Result
     */
    @PostMapping("/list")
    public PageResult2 list(@RequestBody OrderEntity entity) {
        tOrderService.setStoreId2(entity);//设置商家id
        Page<TOrder> queryPage = new Page<>(entity.getPage(), entity.getSize());
        return PageUtil.getPageResult2(tOrderService.list(queryPage, entity));
    }

    /**
     * @Description 订单导出列表
     * @Date 2024/9/22 21:54
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list_export")
    public Result listExport(@RequestBody OrderEntity entity) {
        tOrderService.setStoreId2(entity);//设置商家id
        return ResultGenerator.genSuccessResult(tOrderService.listExport(entity));
    }

    /**
     * @Description 添加订单协议
     * @Date 2024/8/24 10:12
     * @Author YWX
     * @Param [contract]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/add_contract")
    public Result addContract(@RequestBody TOrderContract contract) {
        ToolUtils.validation(new Object[]{
                contract.getOrderId(), "订单id", 1
                , contract.getType(), "类型", 1
                , contract.getPath(), "路径", 1
        });
        tOrderService.addContract(contract);
        return ResultGenerator.genSuccessResult("保存成功！");
    }

    /**
     * @Description 订单协议列表
     * @Date 2024/8/24 16:00
     * @Author YWX
     * @Param [contract]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list_contract")
    public Result listContract(@RequestBody TOrderContract contract) {
        Integer orderId = contract.getOrderId();
        ToolUtils.validation(new Object[]{
                orderId, "订单id", 1
        });
        return ResultGenerator.genSuccessResult("查询成功！", tOrderService.listContract(orderId));
    }

    /**
     * @Description 删除订单协议
     * @Date 2024/9/15 20:38
     * @Author YWX
     * @Param [contract]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/delete_contract")
    public Result deleteContract(@RequestBody TOrderContract contract) {
        Integer ocid = contract.getOcid();
        ToolUtils.validation(new Object[]{
                ocid, "订单协议id", 1
        });
        tOrderService.deleteContract(ocid);
        return ResultGenerator.genSuccessResult("删除成功！");
    }

    /**
     * @Description 订单分配
     * @Date 2024/8/24 10:25
     * @Author YWX
     * @Param [order]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/set_manager")
    public Result setManager(@RequestBody TOrder order) {
        ToolUtils.validation(new Object[]{
                order.getOrderId(), "订单id", 1
                , order.getManagerId(), "负责人id", 1
        });
        tOrderService.setManager(order);
        return ResultGenerator.genSuccessResult("保存成功！");
    }

    /**
     * @Description 补订单
     * @Date 2024/8/26 8:49
     * @Author YWX
     * @Param [order]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/supplement_order")
    public Result supplementOrder(@RequestBody OrderOperate order) {
        ToolUtils.validation(new Object[]{
                order.getOrderId(), "订单id", 1
                , order.getOrderType(), "类型", 1
                , order.getRent(), "租金", 2
                , order.getPlanBegin(), "预计开始时间", 2
                , order.getPlanEnd(), "预计结束时间", 2
        });
        tOrderService.supplementOrder(order);
        return ResultGenerator.genSuccessResult("保存成功！");
    }

    /**
     * @Description 账单退款
     * @Date 2024/10/30 22:31
     * @Author YWX
     * @Param [bill]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/bill_refund")
    public Result billRefund(@RequestBody TOrderBill bill) {
        Integer obid = bill.getObid();
        ToolUtils.validation(new Object[]{obid, "账单id", 1});
        tOrderService.billRefund(obid);
        return ResultGenerator.genSuccessResult("退款成功！");
    }

    /**
     * @Description 获取可退款账单列表
     * @Date 2024/11/1 22:23
     * @Author YWX
     * @Param [bill]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list_bill_for_refund")
    public Result listBillForRefund(@RequestBody TOrderBill bill) {
        Integer orderId = bill.getOrderId();
        ToolUtils.validation(new Object[]{orderId, "订单id", 1});
        return ResultGenerator.genSuccessResult("获取成功！", tOrderService.listBillForRefund(orderId));
    }

    /**
     * @Description 订单退款
     * @Date 2024/11/1 22:31
     * @Author YWX
     * @Param [log]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/order_refund")
    public Result orderRefund(@RequestBody TOrderLog log) {
        ToolUtils.validation(new Object[]{log.getOrderCode(), "订单号", 2});
        TOrderRecord record = new TOrderRecord();
        record.setOrderCode(log.getOrderCode());
        record.setRtype(2);
        record.setAmount(log.getAmount());
        record.setComm(log.getComm());
        record.setFilePath(log.getFilePath());
        List<Integer> obids = log.getObids();
        if (ToolUtils.isListNotEmpty(obids)) {
            record.setObids(obids.stream().map(Object::toString).collect(Collectors.joining(",")));
        }
        record.setObid(log.getObid());
        record.setAmount(log.getAmount());
        tOrderService.addRecord(record);
        return ResultGenerator.genSuccessResult("已申请！");
    }

    /**
     * @Description 重新生成指定账单
     * @Date 2024/10/31 0:21
     * @Author YWX
     * @Param [bill]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/re_generate_bill")
    public Result reGenerateBill(@RequestBody TOrderBill bill) {
        Integer obid = bill.getObid();
        ToolUtils.validation(new Object[]{obid, "账单id", 1});
        tOrderService.reGenerateBill(obid);
        return ResultGenerator.genSuccessResult("生成成功！");
    }

    /**
     * @Description 获取可退款金额
     * @Date 2024/10/30 23:16
     * @Author YWX
     * @Param [order]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/get_refundable_amount")
    public Result getRefundableAmount(@RequestBody TOrder order) {
        String orderCode = order.getOrderCode();
        ToolUtils.validation(new Object[]{orderCode, "订单号", 2});
        return ResultGenerator.genSuccessResult("查询成功！", tOrderService.getRefundableAmount(orderCode));
    }

    /**
     * @Description 修改账单金额
     * @Date 2024/8/26 10:03
     * @Author YWX
     * @Param [bill]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/update_bill_amount")
    public Result updateBillAmount(@RequestBody TOrderBill bill) {
        ToolUtils.validation(new Object[]{
                bill.getOrderCode(), "订单号", 2
                , bill.getPeriod(), "期数", 1
                , bill.getBillAmount(), "金额", 2
        });
        TOrderRecord record = new TOrderRecord();
        record.setOrderCode(bill.getOrderCode());
        record.setRtype(3);
        record.setPeriod(bill.getPeriod());
        record.setAmount(bill.getBillAmount());
        String comm = "修改第" + bill.getPeriod() + "期账单金额为：" + bill.getBillAmount() + "元";
        String billComm = bill.getComm();
        if (ToolUtils.isNotEmpty(billComm)) {
            comm = comm + "，备注：" + billComm;
        }
        record.setComm(comm);
        record.setFilePath(bill.getFilePath());
        tOrderService.addRecord(record);
        return ResultGenerator.genSuccessResult("已申请！");
    }

    /**
     * @Description 修改账单支付状态
     * @Date 2024/8/26 11:07
     * @Author YWX
     * @Param [bill]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/update_bill_status")
    public Result updateBillStatus(@RequestBody TOrderBill bill) {
        ToolUtils.validation(new Object[]{
                bill.getOrderCode(), "订单号", 2
                , bill.getPeriod(), "期数", 1
                , bill.getBillStatus(), "账单状态", 2
        });
        TOrderRecord record = new TOrderRecord();
        record.setOrderCode(bill.getOrderCode());
        record.setRtype(4);
        record.setPeriod(bill.getPeriod());
        record.setBillStatus(bill.getBillStatus());
        String status = "";
        if (bill.getBillStatus() == 1) {
            status = "已支付";
        } else {
            status = "未支付";
        }
        String comm = "修改第" + bill.getPeriod() + "期账单支付状态为：" + status;
        String billComm = bill.getComm();
        if (ToolUtils.isNotEmpty(billComm)) {
            comm = comm + "，备注：" + billComm;
        }
        record.setComm(comm);
        record.setFilePath(bill.getFilePath());
        record.setAmount(bill.getPayAmount());
        tOrderService.addRecord(record);
        return ResultGenerator.genSuccessResult("已申请！");
    }

    /**
     * @Description 冻结押金转支付
     * @Date 2024/8/26 16:55
     * @Author YWX
     * @Param [order]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/convert_deposit_to_payment")
    public Result convertDepositToPayment(@RequestBody TOrder order) {
        ToolUtils.validation(new Object[]{
                order.getOrderCode(), "订单号", 2
        });
        TOrderRecord record = new TOrderRecord();
        record.setOrderCode(order.getOrderCode());
        record.setRtype(6);
        record.setComm("冻结押金转支付");
        tOrderService.addRecord(record);
        return ResultGenerator.genSuccessResult("已申请！");
    }

    /**
     * @Description 修改租期
     * @Date 2024/8/26 15:18
     * @Author YWX
     * @Param [bill]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/update_period")
    public Result updatePeriod(@RequestBody TOrderBill bill) {
        ToolUtils.validation(new Object[]{
                bill.getOrderCode(), "订单号", 2
                , bill.getPeriod(), "申请更换前的租期", 1
                , bill.getNewPeriod(), "申请更换后的期数", 1
        });
        TOrderRecord record = new TOrderRecord();
        record.setOrderCode(bill.getOrderCode());
        record.setRtype(5);
        record.setPeriod(bill.getPeriod());
        record.setNewPeriod(bill.getNewPeriod());
        record.setComm(bill.getComm());
        tOrderService.addRecord(record);
        return ResultGenerator.genSuccessResult("已申请！");
    }

    /**
     * @Description 操作日志
     * @Date 2024/8/26 10:24
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.PageResult2
     **/
    @PostMapping("/list_log")
    public PageResult2 listLog(@RequestBody OrderEntity entity) {
        ToolUtils.validation(new Object[]{entity.getOrderCode(), "订单号", 2});
        Page<TOrderLog> queryPage = new Page<>(entity.getPage(), entity.getSize());
        return PageUtil.getPageResult2(tOrderService.listLog(queryPage, entity));
    }

    /**
     * @Description 账单列表
     * @Date 2024/8/26 11:25
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.PageResult2
     **/
    @PostMapping("/list_bill")
    public PageResult2 listBill(@RequestBody OrderEntity entity) {
        Page<TOrderLog> queryPage = new Page<>(entity.getPage(), entity.getSize());
        return PageUtil.getPageResult2(tOrderService.listBill(queryPage, entity));
    }

    /**
     * @Description 单个订单账单列表
     * @Date 2024/12/31 22:30
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list_order_bill")
    public Result listOrderBill(@RequestBody OrderEntity entity) {
        String orderCode = entity.getOrderCode();
        ToolUtils.validation(new Object[]{orderCode, "订单号", 2});
        return ResultGenerator.genSuccessResult(tOrderService.listOrderBill(orderCode));
    }

    /**
     * @Description 账单导出列表
     * @Date 2024/8/26 11:39
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list_export_bill")
    public Result listExportBill(@RequestBody OrderEntity entity) {
        return ResultGenerator.genSuccessResult(tOrderService.listExportBill(entity));
    }

    /**
     * @Description 逾期订单列表
     * @Date 2024/8/26 22:55
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.PageResult2
     **/
    @PostMapping("/list_expected")
    public PageResult2 listExpected(@RequestBody OrderEntity entity) {
        Page<TOrder> queryPage = new Page<>(entity.getPage(), entity.getSize());
        return PageUtil.getPageResult2(tOrderService.listExpected(queryPage, entity));
    }

    /**
     * @Description 逾期订单导出列表
     * @Date 2024/12/17 22:53
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list_export_expected")
    public Result listExportExpected(@RequestBody OrderEntity entity) {
        return ResultGenerator.genSuccessResult(tOrderService.listExportExpected(entity));
    }

    /**
     * @Description 标记逾期订单
     * @Date 2024/8/26 22:59
     * @Author YWX
     * @Param [tOrder]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/edit_tags")
    public Result editTags(@RequestBody TOrder tOrder) {
        ToolUtils.validation(new Object[]{tOrder.getOrderId(), "id", 1, tOrder.getTags(), "标记", 2});
        TOrder order = new TOrder();
        order.setOrderId(tOrder.getOrderId());
        order.setTags(tOrder.getTags());
        tOrderService.editTags(order);
        return ResultGenerator.genSuccessResult("更新成功！");
    }

    /**
     * @Description 买断订单列表
     * @Date 2024/8/27 9:40
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.PageResult2
     **/
    @PostMapping("/list_buyout")
    public PageResult2 listBuyout(@RequestBody OrderEntity entity) {
        tOrderService.setStoreId(entity);//设置商家id
        Page<TOrder> queryPage = new Page<>(entity.getPage(), entity.getSize());
        return PageUtil.getPageResult2(tOrderService.listBuyout(queryPage, entity));
    }

    /**
     * @Description 买断记录
     * @Date 2024/9/10 22:33
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.PageResult2
     **/
    @PostMapping("/list_buyout_record")
    public PageResult2 listBuyoutRecord(@RequestBody OrderEntity entity) {
        tOrderService.setStoreId(entity);//设置商家id
        Page<TOrder> queryPage = new Page<>(entity.getPage(), entity.getSize());
        entity.setBuyoutStatus(2);
        return PageUtil.getPageResult2(tOrderService.listBuyout(queryPage, entity));
    }

    /**
     * @Description 审核买断订单
     * @Date 2024/8/27 15:10
     * @Author YWX
     * @Param [order]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/check_buyout")
    public Result checkBuyout(@RequestBody TOrder order) {
        Integer orderId = order.getOrderId();
        ToolUtils.validation(new Object[]{
                orderId, "订单id", 1
                , order.getCheckStatus(), "审核状态", 1
        });
        tOrderService.checkBuyout(order);
        return ResultGenerator.genSuccessResult("更新成功！");
    }

    /**
     * @Description 订单付款详情
     * @Date 2024/8/27 21:17
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/detail_pay")
    public Result detailPay(@RequestBody OrderEntity entity) {
        Integer orderId = entity.getOrderId();
        ToolUtils.validation(new Object[]{
                orderId, "订单id", 1
        });
        return ResultGenerator.genSuccessResult("查询成功！", tOrderService.detailPay(orderId));
    }

    /**
     * @Description 取消订单
     * @Date 2024/9/5 0:32
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/cancel_order")
    public Result cancelOrder(@RequestBody OrderEntity entity) {
        Integer orderId = entity.getOrderId();
        ToolUtils.validation(new Object[]{
                orderId, "订单id", 1
        });
        tOrderService.cancelOrder(orderId);
        return ResultGenerator.genSuccessResult("取消成功！");
    }

    /**
     * @Description 获取客户认证信息
     * @Date 2024/9/9 23:19
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/detail_auth")
    public Result detailAuth(@RequestBody OrderEntity entity) {
        Integer customerid = entity.getCustomerid();
        ToolUtils.validation(new Object[]{customerid, "客户id", 1});
        return ResultGenerator.genSuccessResult("查询成功", tOrderService.detailAuth(customerid));
    }

    /**
     * @Description 首页-订单统计
     * @Date 2024/9/12 12:39
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/get_analyze")
    public Result getAnalyze() {
        return ResultGenerator.genSuccessResult("查询成功", tOrderService.getAnalyze());
    }

    /**
     * @Description 首页-续租率
     * @Date 2024/9/13 12:26
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/get_renew_rate")
    public Result getRenewRate(@RequestBody OrderEntity entity) {
        ToolUtils.validation(new Object[]{entity.getType(), "类型", 1});
        return ResultGenerator.genSuccessResult("查询成功", tOrderService.getRenewRate(entity));
    }

    /**
     * @Description 首页-收益走势
     * @Date 2024/9/17 23:20
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/get_earnings_trend")
    public Result getEarningsTrend(@RequestBody OrderEntity entity) {
        ToolUtils.validation(new Object[]{entity.getBegindate(), "开始日期", 2, entity.getEnddate(), "结束日期", 2});
        return ResultGenerator.genSuccessResult("查询成功", tOrderService.getEarningsTrend(entity));
    }

    /**
     * @Description 首页-订单走势
     * @Date 2024/9/18 23:40
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/get_order_trend")
    public Result getOrderTrend(@RequestBody OrderEntity entity) {
        ToolUtils.validation(new Object[]{entity.getBegindate(), "开始日期", 2, entity.getEnddate(), "结束日期", 2});
        return ResultGenerator.genSuccessResult("查询成功", tOrderService.getOrderTrend(entity));
    }

    /**
     * @Description 审核风控
     * @Date 2024/9/24 21:33
     * @Author YWX
     * @Param [tOrder]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/check_control")
    public Result checkControl(@RequestBody TOrder tOrder) {
        ToolUtils.validation(new Object[]{tOrder.getOrderId(), "订单id", 1, tOrder.getControlStatus(), "风控状态", 1});
        tOrderService.checkControl(tOrder);
        return ResultGenerator.genSuccessResult("确认成功！");
    }

    /**
     * @Description 获取风控报告
     * @Date 2024/9/17 17:25
     * @Author YWX
     * @Param [tOrder]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/get_control_report")
    public Result getControlReport(@RequestBody TOrder tOrder) {
        Integer orderId = tOrder.getOrderId();
        ToolUtils.validation(new Object[]{orderId, "订单id", 1});
        return ResultGenerator.genSuccessResult("获取成功！", tOrderService.getControlReport(orderId));
    }

    /**
     * @Description 完结订单
     * @Date 2024/9/30 13:11
     * @Author YWX
     * @Param [tOrder]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/end")
    public Result end(@RequestBody TOrder tOrder) {
        Integer orderId = tOrder.getOrderId();
        ToolUtils.validation(new Object[]{orderId, "订单id", 1});
        tOrderService.end(orderId);
        return ResultGenerator.genSuccessResult("完结成功！");
    }

    /**
     * @Description 确认收货
     * @Date 2024/10/25 15:12
     * @Author YWX
     * @Param [tOrder]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/confirm_receipt")
    public Result confirmReceipt(@RequestBody TOrder tOrder) {
        String orderCode = tOrder.getOrderCode();
        ToolUtils.validation(new Object[]{orderCode, "订单号", 2});
        tOrderService.confirmReceipt(orderCode);
        return ResultGenerator.genSuccessResult("确认成功！");
    }

    /**
     * @Description 审核取消订单
     * @Date 2024/10/9 23:15
     * @Author YWX
     * @Param [tOrder]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/check_cancel")
    public Result checkCancel(@RequestBody TOrder tOrder) {
        Integer cancelCheckStatus = tOrder.getCancelCheckStatus();
        ToolUtils.validation(new Object[]{tOrder.getOrderCode(), "订单号", 2, cancelCheckStatus, "状态", 1});
        if (!cancelCheckStatus.equals(2) && !cancelCheckStatus.equals(3)) {
            return ResultGenerator.genFailResult("未选择审批结果！");
        }
        tOrderService.checkCancel(tOrder);
        return ResultGenerator.genSuccessResult("审核成功！");
    }

    /**
     * @Description 申请取消信息
     * @Date 2024/10/9 23:37
     * @Author YWX
     * @Param [tOrder]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/detail_cancel")
    public Result detailCancel(@RequestBody TOrder tOrder) {
        String orderCode = tOrder.getOrderCode();
        ToolUtils.validation(new Object[]{orderCode, "订单号", 2});
        return ResultGenerator.genSuccessResult("查询成功！", tOrderService.detailCancel(orderCode));
    }

    /**
     * @Description 账单发起代扣
     * @Date 2024/10/22 22:28
     * @Author YWX
     * @Param [bill]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/deposit_to_payment_by_obid")
    public Result depositToPaymentByObid(@RequestBody TOrderBill bill) {
        Integer obid = bill.getObid();
        ToolUtils.validation(new Object[]{
                obid, "订单账单id", 1
        });
        tOrderService.depositToPaymentByObid(obid);
        return ResultGenerator.genSuccessResult("代扣成功！");
    }

    /**
     * @Description 申请续租
     * @Date 2024/10/26 22:31
     * @Author YWX
     * @Param [bill]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/renew_lease")
    public Result renewLease(@RequestBody OrderBillEntity bill) {
        ToolUtils.validation(new Object[]{
                bill.getOrderCode(), "订单号", 2
                , bill.getEndTime(), "结束日期", 1
                , bill.getRent(), "总租金", 2
                , bill.getInRent(), "输入的总租金", 2
        });
        TOrderRecord record = new TOrderRecord();
        record.setOrderCode(bill.getOrderCode());
        record.setRtype(1);
        record.setEndTime(bill.getEndTime());
        record.setComm(bill.getComm());
        record.setAmount(bill.getRent());
        record.setInAmount(bill.getInRent());
        tOrderService.addRecord(record);
        return ResultGenerator.genSuccessResult("已申请！");
    }

    /**
     * @Description 修改收货地址
     * @Date 2024/10/26 23:15
     * @Author YWX
     * @Param [order]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/update_user_address")
    public Result updateUserAddress(@RequestBody TOrder order) {
        String orderCode = order.getOrderCode();
        String userAddress = order.getUserAddress();
        String username = order.getUsername();
        String userphone = order.getUserphone();
        ToolUtils.validation(new Object[]{
                orderCode, "订单号", 2
                , userAddress, "收货地址", 1
        });
        tOrderService.updateUserAddress(orderCode, userAddress, username, userphone);
        return ResultGenerator.genSuccessResult("修改成功！");
    }

    /**
     * @Description 获取订单状态数量
     * @Date 2024/10/27 10:54
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/get_status_num")
    public Result getStatusNum(@RequestBody OrderEntity entity) {
        tOrderService.setStoreId2(entity);//设置商家id
        return ResultGenerator.genSuccessResult(tOrderService.getStatusNum(entity));
    }

    /**
     * @Description 获取订单分配人
     * @Date 2024/10/27 16:59
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list_manager")
    public Result listManager(@RequestBody OrderEntity entity) {
        tOrderService.setStoreId2(entity);//设置商家id
        return ResultGenerator.genSuccessResult(tOrderService.listManager(entity));
    }

    /**
     * @Description 添加订单备注
     * @Date 2024/10/28 21:53
     * @Author YWX
     * @Param [comm]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/add_comm")
    public Result addComm(@RequestBody TOrderComm comm) {
        ToolUtils.validation(new Object[]{
                comm.getOrderCode(), "订单号", 2
                , comm.getComm(), "备注", 1
        });
        tOrderService.addComm(comm);
        return ResultGenerator.genSuccessResult("保存成功！");
    }

    /**
     * @Description 订单备注列表
     * @Date 2024/10/28 21:56
     * @Author YWX
     * @Param [comm]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list_order_comm")
    public Result listOrderComm(@RequestBody TOrderComm comm) {
        String orderCode = comm.getOrderCode();
        ToolUtils.validation(new Object[]{
                orderCode, "订单号", 2
        });
        return ResultGenerator.genSuccessResult("查询成功！", tOrderService.listOrderComm(orderCode));
    }

    /**
     * @Description 获取续租实付金额
     * @Date 2024/11/7 22:09
     * @Author YWX
     * @Param [bill]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/get_renew_lease_price")
    public Result getRenewLeasePrice(@RequestBody OrderBillEntity bill) {
        ToolUtils.validation(new Object[]{
                bill.getOrderCode(), "订单号", 2
                , bill.getEndTime(), "结束日期", 1
        });
        return ResultGenerator.genSuccessResult("查询成功！", tOrderService.getRenewLeasePrice(bill));
    }

    /**
     * @Description 修改订单租期
     * @Date 2024/11/9 22:55
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/update_order_period")
    public Result updateOrderPeriod(@RequestBody OrderBillEntity entity) {
        ToolUtils.validation(new Object[]{
                entity.getOrderCode(), "订单号", 2
                , entity.getBegindate(), "开始时间", 2
        });
        tOrderService.updateOrderPeriod(entity);
        return ResultGenerator.genSuccessResult("租期修改成功！");
    }

    /**
     * @Description 根据客户ID获取客户姓名和身份证号码
     * @Date 2024/11/16 22:25
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/get_name_id")
    public Result getNameAndIdNumber(@RequestBody OrderEntity entity) {
        Integer customerid = entity.getCustomerid();
        ToolUtils.validation(new Object[]{
                customerid, "客户id", 1
        });
        return ResultGenerator.genSuccessResult("查下成功！", tOrderService.getNameAndIdNumber(customerid));
    }

    /**
     * @Description 新增订单申请记录
     * @Date 2024/12/18 22:20
     * @Author YWX
     * @Param [record]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/add_record")
    public Result addRecord(@RequestBody TOrderRecord record) {
        tOrderService.addRecord(record);
        return ResultGenerator.genSuccessResult("保存成功！");
    }

    /**
     * @Description 审核订单申请记录
     * @Date 2024/12/18 22:20
     * @Author YWX
     * @Param [record]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/check_record")
    public Result checkRecord(@RequestBody TOrderRecord record) {
        ToolUtils.validation(new Object[]{record.getOrid(), "记录id", 1, record.getCheckStatus(), "审核状态", 1});
        tOrderService.checkRecord(record);
        return ResultGenerator.genSuccessResult("更新成功！");
    }

    /**
     * @Description 订单申请记录列表
     * @Date 2024/12/19 21:33
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.PageResult2
     **/
    @PostMapping("/list_record")
    public PageResult2 listRecord(@RequestBody OrderEntity entity) {
        Page<TGoods> queryPage = new Page<>(entity.getPage(), entity.getSize());
        return PageUtil.getPageResult2(tOrderService.listRecord(queryPage, entity));
    }

    /**
     * @Description 获取用户信息
     * @Date 2025/1/18 22:10
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/user_info")
    public Result getUserInfo(@RequestBody OrderEntity entity) {
        String orderCode = entity.getOrderCode();
        ToolUtils.validation(new Object[]{orderCode, "订单号", 2});
        return ResultGenerator.genSuccessResult("查下成功！", tOrderService.getUserInfo(orderCode));
    }

    /**
     * @Description 补充用户资料
     * @Date 2025/1/23 23:04
     * @Author YWX
     * @Param [auth]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/update_user_profile")
    public Result updateUserProfile(@RequestBody TCustomerAuth auth) {
        ToolUtils.validation(new Object[]{auth.getCustomerid(), "客户id", 1});
        tOrderService.updateUserProfile(auth);
        return ResultGenerator.genSuccessResult("补充资料成功！");
    }
}
